package com.thinkgem.jeesite.common.frame.rpc.process.impl;

import com.thinkgem.jeesite.common.frame.rpc.annotation.RPCBeanDefinition;
import com.thinkgem.jeesite.common.frame.rpc.bean.RPCInData;
import com.thinkgem.jeesite.common.frame.rpc.factory.RPCWebServiceFactory;
import com.thinkgem.jeesite.common.frame.rpc.process.IRPCProcess;
import com.thinkgem.jeesite.common.utils.SpringContextHolder;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * Created by liufeng on 2016/6/7.
 */
@Component
public class RPCProcess implements IRPCProcess{
    @Override
    public void process(RPCInData inData) {



        String scope = inData.getRpcHeader().getScope();
        String sys = inData.getRpcHeader().getSys();
        String module = inData.getRpcHeader().getModule();
        String cmd = inData.getRpcHeader().getMethod();

        RPCBeanDefinition rpcBeanDefinition = RPCWebServiceFactory.getRPCWebService("${webServicePath}."+scope+"."+sys+"."+module+"."+cmd);

        try {
            rpcBeanDefinition.getMethodRef().invoke(SpringContextHolder.getBean(rpcBeanDefinition.getClassRef()),inData);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }


    }
}
